package view;

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import controler.SistemaIndumentaria;

public class AltaSinTemporada extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel lblCodigo;
	private JTextField txtCodigo;
	private JLabel lblNombre;
	private JTextField txtNombre;
	private JButton btnCalcularPrecio;
	private JLabel lblPrecio;
	private JTextField txtPrecio;
	private JButton btnAgregar;
	private JButton btnConfirmar;
	private JButton btnCerrar;
	private Container contenedor;
	
	public AltaSinTemporada(){
		this.setVisible(true);
		setBounds(300, 300, 450, 300);
		this.setLocationRelativeTo(null);
		this.setTitle("Agregar nueva prenda Sin Temporada");
		this.setLayout(new GridLayout(12,12));
		
		final Container contenedor = this.getContentPane();
		
		lblCodigo = new JLabel();
		lblCodigo.setText("Codigo");
		contenedor.add(lblCodigo);
		
		txtCodigo = new JTextField();
		txtCodigo.setSize(30,100);
		contenedor.add(txtCodigo);
		
		lblNombre = new JLabel();
		lblNombre.setText("Nombre:");
		contenedor.add(lblNombre);
		
		txtNombre = new JTextField();
		txtNombre.setSize(30,100);
		contenedor.add(txtNombre);
		
		
		btnCalcularPrecio = new JButton();
		btnCalcularPrecio.setText("Calcular Precio");
		btnCalcularPrecio.setVisible(false);
		btnCalcularPrecio.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				
				lblPrecio = new JLabel();
				lblPrecio.setText("Precio:");
				contenedor.add(lblPrecio);
				
				txtPrecio = new JTextField();
				txtPrecio.setSize(30,100);
				contenedor.add(txtPrecio);
				txtPrecio.setText(String.valueOf(SistemaIndumentaria.getInstancia().calcularPrecioPrenda(Integer.parseInt(txtCodigo.getText()))));
				
				
				btnConfirmar.setVisible(true);
			}
		});
		contenedor.add(btnCalcularPrecio);
		
		
		btnAgregar = new JButton();
		btnAgregar.setText("Agregar");
		btnAgregar.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				
				if((!txtCodigo.getText().equalsIgnoreCase(""))&&(!txtNombre.getText().equalsIgnoreCase(""))){
					if(SistemaIndumentaria.getInstancia().altaPrendaSinTemporada(Integer.parseInt(txtCodigo.getText()),txtNombre.getText()))
					{
						AgregarMaterialYCantidad a = new AgregarMaterialYCantidad(Integer.parseInt(txtCodigo.getText()));
						a.setVisible(true);
						btnCalcularPrecio.setVisible(true);
					}
				}
				else{
					JOptionPane.showMessageDialog(AltaSinTemporada.this.contenedor,"Todos los campos son requeridos",
					    "Campos vacios",
					    JOptionPane.ERROR_MESSAGE); 
				}					
					
				
				
			}
		});
		contenedor.add(btnAgregar);
		
		btnConfirmar = new JButton();
		btnConfirmar.setText("Confirmar Prenda");
		btnConfirmar.setVisible(false);
		btnConfirmar.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				SistemaIndumentaria.getInstancia().confirmarPrendaSinTemporada(Integer.parseInt(txtCodigo.getText()));
				
			}
			
		}
				
		);
		contenedor.add(btnConfirmar);
	
	btnCerrar = new JButton();
	btnCerrar.setText("Cerrar");
	contenedor.add(btnCerrar);	
	btnCerrar.addActionListener(new ActionListener() {
		
		public void actionPerformed(ActionEvent e) {

			AltaSinTemporada.this.setVisible(false);
		}
	});
	}
}
